using UnityEngine;
using System.Collections.Generic;

public class Wall : BaseBehaviour
{
	private WallBlockWay wallBlockWay;
    private WallBlock[] blocks;

    public IList<GameObjectTransform> getBlocks()
    {
        IList<GameObjectTransform> result = new List<GameObjectTransform>();

        foreach (WallBlock each in blocks)
            result.Add(each);

        return result;
    }

    protected override void start()
    {
        createBlockWay();
        startBlocks();

        base.start();
    }

    private void createBlockWay()
    {
        WallBlockWayFactory wallBlockWayFactory = new WallBlockWayFactory();
        wallBlockWay = wallBlockWayFactory.create();
    }

    private void startBlocks()
	{
        storeBlocks();
        initializeBlocks();
	}

    private void storeBlocks()
    {
        blocks = gameObject.transform.GetComponentsInChildren<WallBlock>();
    }
   
    private void initializeBlocks()
    {
        WallBlock lastBlock = blocks[blocks.Length - 1];

        foreach (WallBlock each in blocks)
        {
            each.init(wallBlockWay, lastBlock);
            lastBlock = each;
        }
    }
}